// pages/image1/index.js
var t = getApp(),
  a = t.requirejs("core");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    route: "book_list",
    menu: t.tabBar,
    menu_show: false,
    loaded: false,
    show: false,
    list: [],
    page: 1
  },
  //底部导航跳转
  menu_url: function (k) {
    a.menu_url(k, 2);
  },
  onLoad: function (e) {

    if (e != null && e != undefined) {
      this.setData({
        tabbar_index: e.tabbar_index ? e.tabbar_index : -1
      });
    }

    a.setting();
    this.setData({
      menu: getApp().tabBar,
    })

    if (this.data.tabbar_index >= 0) {
      this.setData({
        showtabbar: true,
      })
    }
    this.getlist()
  },
  to_url:function(t){
    var that=this,
    list=that.data.list,
    index=a.pdata(t).index;
    a.jump('/yb_shop/pages/book_info/index?data=' + JSON.stringify(list[index]));
  },
  getlist: function () {
    var that = this,
      page = that.data.page;
    a.get('Market/booklist',{page:page},function(t){
      if(t.code==0){
        if (t.info.length > 0)
          {
            that.setData({
              list: that.data.list.concat(t.info),
              show: true,
              page: page + 1,
            }) 
          }
          else
          {
            that.setData({
              loaded: true,
            })
          }
           
      }else{
        a.alert(t.msg);
      }
    })
  },
  
 
  /**
    * 下拉刷新
    */
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      page: 1,
      loaded:false
    })
    this.getlist()
    wx.stopPullDownRefresh();
  },
  /**
   *上拉加载
   */
  onReachBottom: function () {
    console.log('加载更多')
    this.data.loaded || this.getlist()
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})